﻿@model IEnumerable<blog_article>
@using Yqblog.Data
@using res = Resource.Admin.Admin;
@{
    var navkey = res.Article;
    switch ((string)ViewBag.NavSelectedItem)
    {
        case "article":
            navkey = res.Article;
            break;
        case "singlePage":
            navkey = res.SinglePage;
            break;
        case "album":
            navkey = res.Album;
            break;
        case "message":
            navkey = res.Note;
            break;
        case "comment":
            navkey = res.Comment;
            break;
        case "posts":
            navkey = res.Posts;
            break;
        case "reply":
            navkey = res.Reply;
            break;
        case "customArea":
            navkey = res.CustomArea;
            break;
        case "customGlobalArea":
            navkey = res.CustomGlobalArea;
            break;
    }
}
<h1 class="page-title">
    @navkey					
</h1>
<div class="row-fluid @ViewBag.NavSelectedItem">
    <ul class="nav-filters span8">
        <li>
            <ul class="nav nav-pills sortbtn">
                @if (ViewBag.LayerId != 1 && ViewBag.TypeId != 6)
                {
                    <li><a href="###" p="all">@res.All</a> </li>
                                         if (ViewBag.TypeId == 1 || ViewBag.TypeId == 4)
                                         {
                        <li><a href="###" p="normal" >@res.Normal</a> </li>
                        <li><a href="###" p="draft" >@res.Draft</a> </li>
                        <li><a href="###" p="istop" >@res.Top</a> </li>
                        <li><a href="###" p="iscommend" >@res.Recommend</a> </li>
                                         }
                                         else if (ViewBag.TypeId == 2 || ViewBag.TypeId == 7 || ViewBag.TypeId == 8)
                                         {
                        <li><a href="###" p="normal" >@res.Normal</a> </li>
                        <li><a href="###" p="draft" >@res.Draft</a> </li>
                                         }
                }
                @if (ViewBag.LayerId == 1 && (ViewBag.TypeId == 1 || ViewBag.TypeId == 4))
                {
                    <li  @if (ViewBag.TypeId == 1)
                                 {
                                     @Html.Raw("class=\"active\"");
                                 }>@Html.ActionLink(res.ArticleComment, "AdminArticle", "Admin", new { layer = 1, tid = 1 }, null)</li>
                    <li @if (ViewBag.TypeId == 4)
                                 {
                                     @Html.Raw("class=\"active\"");
                                 }> @Html.ActionLink(res.AlbumComment, "AdminArticle", "Admin", new { layer = 1, tid = 4 }, null) </li>
                }
            </ul>
        </li>
        @if (ViewBag.TypeId != 6)
        {<li class="divider-vertical"></li>}
        <li>
            <ul class="nav nav-pills orderbtn">
                <li><a href="###" p="desc">@res.Descending</a></li> 
                <li><a href="###" p="asc">@res.Ascending</a></li>
            </ul>
        </li>
    </ul>
    <div class="span4">
        @if (ViewBag.LayerId != 1 && ViewBag.TypeId != 6)
        {
            <div class="ml10 fright">@Html.ActionLink(res.Add, "AdminAdd", "Admin", new { tid = ViewBag.TypeId, cid = ViewBag.Cid }, new { @class = "btn btn-primary" })</div>
            if (ViewBag.TypeId != 7 && ViewBag.TypeId != 8)
            {
                <div class="fright">@Html.DropDownList("CateId")</div>
            }
        }
    </div>
</div>
<div class="widget">
    <div class="widget-header">
        <h3>@res.Total:@ViewBag.Amount</h3>
        @if (ViewBag.TypeId == 7 || ViewBag.TypeId == 8)
        {
            <div class="pull-right btn_help" id="help_@(ViewBag.TypeId)">?</div>
        }
    </div>									
    <div class="widget-content">
        <div class="pager pagination"></div>
        <table class="table">
            <thead>
                <tr>
                    <th><input type="checkbox" onfocus=" this.blur() " id="allCheck" name="allCheck"/></th>
                    <th class="hide">@res.Id</th>
                    <th>@res.Title</th>
                    <th style="min-width: 90px;">@res.Date</th>
                    <th style="min-width: 150px;">@res.Operating</th>
                </tr>
            </thead>
            <tbody>
                @if (Model.Any())
                {
                    foreach (var item in Model)
                    {
                        <tr id="@item.id">
                            <td>
                                <input type="checkbox" onfocus=" this.blur() " value="@item.id" pid="@item.parentid" name="chkArticle"/>
                            </td>
                            <td class="hide"><a href="#@item.id" name="@item.id">@item.id</a></td>
                            <td>
                                @if (item.layer != 0 || item.typeid == 6)
                                {
                                    <div>
                                        <span class="grayblue">@item.username:</span>
                                        <p> @Html.Raw(item.content)</p>
                                    </div>
                                }
                                else if (item.typeid == 7 || item.typeid == 8)
                                {
                                    @item.title
                                }
                                else
                                {
                                    <a href="@Html.YqUrl(item)" title="@item.title" target="_blank">@item.title</a>
                                }
                            </td>
                            <td>@Html.GetDate(item.createdate)</td>
                            <td><ul>
                                    @if (item.layer == 0 && item.typeid != 6)
                                    {
                                        @Html.ActionLink(res.Edit, "AdminEdit", "Admin", new { item.id }, new { @class = "btn btn-success" })
                                    }
                                    <a href="javascript:" class="btn btn-danger" onclick=" Del(@item.id, @item.parentid) ">@res.Delete</a> 
                                </ul>
                            </td>
                        </tr>
                    }
                }
            </tbody></table>
        <div class="pager pagination"></div>
        <p>
            <a class="deleteLink BatchDelete" href="javascript:;">@res.DeleteSelected</a>
        </p>
    </div> 	
</div>
<div id="ModalDeleteArticle">
    @{Html.RenderPartial("_ModalPopUp");}
</div>
<div id="ModalBatchDeleteArticle">
    @{Html.RenderPartial("_ModalPopUp");}
</div>
<input type="hidden" id="deleteid" name="deleteid" value=""/>
<input type="hidden" id="deleteparentid" name="deleteparentid" value=""/>
@section Js{
    <script src="@Url.Content("~/Scripts/jquery.pager.js")" type="text/javascript"></script>
    <script type="text/javascript">
        var pageNo = @ViewBag.PageNo;
        var pageCount = @ViewBag.PageCount;
        var typeid = @ViewBag.TypeId;
        var layerid = @ViewBag.LayerId;
        var cateid = @ViewBag.Cid;
        var sortpara = "@ViewBag.Sort";
        var orderpara = "@ViewBag.Order";

        var arrayObj = new Array();
        var checkitem = 0;

        $(function() {
            if (pageCount == 0) {
                $(".pager").hide();
            }
            $(".pager").pager({ pagenumber: pageNo, pagecount: pageCount, buttonClickCallback: PageClick });

            $('#CateId').change(function() {
                var p1 = $(this).children('option:selected').val();
                Go("?tid=" + typeid + "&layer=" + layerid + "&cid=" + p1 + "&sort=" + sortpara + "&order=" + orderpara);
            });

            $('.sortbtn a').click(function() {
                var p = $(this).attr("p");
                Go("?tid=" + typeid + "&layer=" + layerid + "&cid=" + cateid + "&sort=" + p + "&order=" + orderpara);
            });

            $('.orderbtn a').click(function() {
                var p = $(this).attr("p");
                Go("?tid=" + typeid + "&layer=" + layerid + "&cid=" + cateid + "&sort=" + sortpara + "&order=" + p);
            });

            $(".sortbtn a").each(function() {
                if ($(this).attr("p") == (sortpara==""?"all":sortpara)) {
                    $(this).parent().addClass("active");
                }
            });

            $(".orderbtn a").each(function() {
                if ($(this).attr("p") == (orderpara==""?"desc":orderpara)) {
                    $(this).parent().addClass("active");
                }
            });

            $('#allCheck').click(function() {
                $("input[name='chkArticle']").prop("checked", $(this).prop("checked"));
            });
            
            $('#ModalDeleteArticle .modal-yes').click(function() {
                $('#ModalDeleteArticle .modal').modal('hide');
                DoDel($('#deleteid').val(),$('#deleteparentid').val());
            });

            $('.BatchDelete').on('click',function() {
                arrayObj = new Array();
                checkitem = 0;
                
                ModalView("ModalBatchDeleteArticle", "@(res.BatchDeleteArticle)", "@(res.Delete_Tip)");
            });

            $('#ModalBatchDeleteArticle .modal-yes').click(function() {
                $('#ModalBatchDeleteArticle .modal').modal('hide');
                $("input[name='chkArticle']").each(function() {
                    if ($(this).prop("checked")) {
                        var itemid = $(this).val();
                        var itempid = $(this).attr("pid");
                        arrayObj.push([itemid, itempid]);
                    }
                });
                DelBatchExec();
            });
        });

        PageClick = function(no) {
            Go("?pageNo=" + no + "&tid=" + typeid + "&layer=" + layerid + "&cid=" + cateid + "&sort=" + sortpara + "&order=" + orderpara);
        };

        Del = function(id, parentid) {
            $('#deleteid').val(id);
            $('#deleteparentid').val(parentid);
            ModalView("ModalDeleteArticle", "@(res.DeleteArticle)", "@(res.DeleteSelected_Tip)");
        };

        DoDel = function(id, parentid) {
            $.post('@Url.Action("AdminDel", "Admin")', { id: id, parentid: parentid }, function() {
                $('#' + id).fadeOut('fast', function() {
                    $(this).remove();
                });
            });
        };

        DelBatchExec = function() {
            if (arrayObj.length > checkitem) {
                $.post('@Url.Action("AdminDel", "Admin")', { id: arrayObj[checkitem][0], parentid: arrayObj[checkitem][1] }, function() {
                    $('#' + arrayObj[checkitem][0]).fadeOut('fast', function() {
                        $(this).remove();
                    });
                    checkitem++;
                    DelBatchExec();
                });
            }
        };

    </script>
}
